package cn.yougou.controller;

import cn.yougou.common.DtoUtil;
import cn.yougou.dto.Dto;
import cn.yougou.pojo.YgCommodityProduct;
import cn.yougou.service.shopcart.YgCommodityProductService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * (YgCommodityProduct)表控制层
 *
 * @author 白杰崇
 * @since 2020-12-11 18:57:42
 */
@RestController
@RequestMapping("ygCommodityProduct")
public class YgCommodityProductController {
    /**
     * 服务对象
     */
    @Reference
    private YgCommodityProductService ygCommodityProductService;


    /**
     * 查询规格不同组合的商品(购物车/类型)
     * 接收的是["1.5m床垫*1+枕头*2","玛瑙红"]规格组合
     * @param specifications
     * @return
     */
    @GetMapping("getProduct")
    public Dto getProduct(String specifications,Integer commodityId){ //商品id,商品组合信息
        Dto dto = null;
        if(commodityId != null && !specifications.equals("")){
            try {
                YgCommodityProduct ygCommodityProduct = new YgCommodityProduct(specifications,commodityId);
                YgCommodityProduct ygProList =  ygCommodityProductService.getProduct(ygCommodityProduct);
                dto = DtoUtil.returnSuccess("获取成功",ygProList);
            }catch (Exception e) {
                e.printStackTrace();
                dto = DtoUtil.returnFail("系统出错","49999");
            }
        }else{
            return DtoUtil.returnFail("缺少必要的参数","50001");
        }
        return dto;
    }

}